package dataMode;

public class QRNum extends QRData {

	public QRNum(String data, int version, int errorCorrectionLevel) {
		super(data, version, errorCorrectionLevel);
		super.mode = QRData.MODE_NUMERIC;
		
		super.encodeDataToBinary();
	}
	
	
	/*Encode la chaine de caract�re en chaine de bit pour le mode NUMERIQUE*/
	protected void encode(){
		int lenghtData = data.length();
		int tmp1;
		int tmp2;
		int tmp3;
		int i = 0;
		StringBuffer tmpBinResult = new StringBuffer();
		
		// Parcours de la chaine de caract�re de 3 en 3
		while(i+2<lenghtData)
		{
			tmp1 = super.getCode(data.charAt(i));
			tmp2 = super.getCode(data.charAt(i+1));
			tmp3 = super.getCode(data.charAt(i+2));
			tmpBinResult.append(addZeroOnLeft(Integer.toBinaryString(tmp1+tmp2+tmp3), 10));
			i+=3;
		}
		
		if (lenghtData - i == 1) {
			tmp1 = super.getCode(data.charAt(i));
			tmpBinResult.append(addZeroOnLeft(Integer.toBinaryString(tmp1), 4));
		} 
		else if (lenghtData - i == 2) {
			tmp1 = super.getCode(data.charAt(i));
			tmp2 = super.getCode(data.charAt(i+1));
			tmpBinResult.append(addZeroOnLeft(Integer.toBinaryString(tmp1+tmp2), 7));
		}
			
		super.binaryData += tmpBinResult.toString();
	}
	
}